package org.bigjava.user.web.controller;

import org.bigjava.bean.Posts;
import org.bigjava.bean.User;
import org.bigjava.user.service.AjaxService;
import org.bigjava.user.service.impl.AjaxServiceImpl;
import org.bigjava.user.service.impl.UserServicesImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/ajaxuser/")
public class AjaxUserController {

    @Autowired
    UserServicesImpl userServices;
    @Autowired
    AjaxServiceImpl ajaxService;

    @RequestMapping("signUserName")
    public boolean signUserName(String userName){
        //查询用户名是否重复
        System.out.println("ajax"+userName);

        boolean a = userServices.queryUserName(userName);
        System.out.println("判断"+a);
        List<User> users = new ArrayList<>();

        return a;
    }

    @RequestMapping("alluser")
    public List<User> newUser(){

        List<User> users = userServices.getAllUser();


        return users;

    }

    @RequestMapping("updateattention")
    public boolean updateAttention(String userId,long topicId){
        //修改用户关注状态  （取消关注/重新关注）
        System.out.println("ajax"+"----"+userId+"---"+topicId);

        boolean a = ajaxService.updateAttention(userId,topicId);
        System.out.println(a);
        return a;
    }

    @RequestMapping("updatecollect")
    public boolean updateCollect(String userId,long postId){

        System.out.println("ajax----"+userId+"-----"+postId);
        boolean a = ajaxService.updateCollect(userId,postId);
        return a;
    }

    @RequestMapping("updatepostprivacy")
    public boolean updatepostprivacy(String userId,long postId){

        System.out.println("ajax----"+userId+"---"+postId);
        boolean a = ajaxService.updatePostPrivacy(postId);

        return a;
    }




}
